//
//  LEBarButtonItem.m
//  CreditAddressBook
//
//  Created by Lee on 15/10/9.
//  Copyright © 2015年 Lee. All rights reserved.
//

#import "LEBarButtonItem.h"
#import "XCTabBarButton.h"

@interface LEBarButtonItem ()

@property (nonatomic , strong) XCTabBarButton *tabBtn;
@property(nonatomic, strong) XCButton *button;
@end

@implementation LEBarButtonItem

- (void)setSelected:(BOOL)selected {
    if (self.tabBtn) {
        self.tabBtn.selected = selected;
    }
    if (self.button) {
        self.button.selected = selected;
    }
}

- (instancetype)initWithImage:(UIImage *)imageName andSelImage:(UIImage *)selImageName andTitle:(NSString *)title target:(id)target action:(SEL)action {
    XCTabBarButton *tabBtn = [[XCTabBarButton alloc] init];
    tabBtn.width = 80;
    tabBtn.height = 50;
    [tabBtn setImage:imageName forState:UIControlStateNormal];
    if (selImageName) {
        [tabBtn setImage:selImageName forState:UIControlStateSelected];
    }
    [tabBtn setTitle:title forState:UIControlStateNormal];
    [tabBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [tabBtn setTitleColor:SELTitleColor  forState:UIControlStateSelected];
    [tabBtn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    self = [super initWithCustomView:tabBtn];
    if (self) {
        self.tabBtn = tabBtn;
    }
    return self;
}

- (instancetype)initWithImage:(UIImage *)imageName andSelImage:(UIImage *)selImageName target:(id)target action:(SEL)action {
    XCButton *tabBtn = [[XCButton alloc] init];
    tabBtn.width = 25;
    tabBtn.height = 25;
    [tabBtn setImage:imageName forState:UIControlStateNormal];
    if (selImageName) {
        [tabBtn setImage:selImageName forState:UIControlStateSelected];
    }
    [tabBtn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    self = [super initWithCustomView:tabBtn];
    if (self) {
        self.button = tabBtn;
    }
    return self;
}

- (instancetype)initWithImagelong:(UIImage *)imageName andSelImage:(UIImage *)selImageName target:(id)target action:(SEL)action {
     XCButton *tabBtn = [[XCButton alloc] init];
     tabBtn.width = 80;
     tabBtn.height = 25;
     [tabBtn setImage:imageName forState:UIControlStateNormal];
     if (selImageName) {
          [tabBtn setImage:selImageName forState:UIControlStateSelected];
     }
     [tabBtn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
     self = [super initWithCustomView:tabBtn];
     if (self) {
          self.button = tabBtn;
     }
     return self;
}

@end
